package com.zlzxm.shoesmarket.net;

import com.zlzxm.shoesmarket.globle.UserManager;
import com.zlzxm.shoesmarket.net.respone.BaseResponse;

import io.reactivex.rxjava3.functions.Consumer;

/**
 * CREATE BY zlzxm ON 2021/5/13
 */
public abstract class BaseCallBack<T> implements Consumer<BaseResponse<T>> {

    protected abstract void succeed(String msg,T t);

    protected abstract void failed(String msg);

    protected abstract void notLogin();

    @Override
    public void accept(BaseResponse<T> response) throws Throwable {

        if(response.getCode() == RequestCode.REQUEST_SUCCEED){

            succeed(response.getMsg(),response.getData());

        }else {

            failed(response.getMsg());

            if(response.getCode() == RequestCode.REQUEST_NEED_LOGIN){

                UserManager.getInstance().loginOut();
                notLogin();

            }

        }


    }
}
